# widget/WordPopup.py
from PyQt6.QtWidgets import QWidget, QVBoxLayout, QLabel, QFrame
from PyQt6.QtCore import Qt


class WordPopup(QWidget):
    """单词释义弹窗"""

    def __init__(self, word, pronunciation, meaning):
        super().__init__()
        self.init_ui(word, pronunciation, meaning)
        self.set_window_properties()

    def init_ui(self, word, pronunciation, meaning):
        # 设置窗口无边框
        self.setWindowFlags(
            Qt.WindowType.FramelessWindowHint |  # 无边框
            Qt.WindowType.WindowStaysOnTopHint |  # 置顶
            Qt.WindowType.ToolTip  # 工具提示样式
        )

        # 设置样式
        self.setStyleSheet("""
            QWidget {
                background-color: white;
                border: 1px solid #CCCCCC;
                border-radius: 8px;
                padding: 5px;
            }
        """)

        # 主布局
        layout = QVBoxLayout()
        layout.setSpacing(5)
        layout.setContentsMargins(10, 10, 10, 10)

        # 中文描述
        meaning_label = QLabel(str(pronunciation + "\n" + meaning))
        meaning_label.setStyleSheet("font-size: 12px; color: #34495e;")
        meaning_label.setWordWrap(True)
        layout.addWidget(meaning_label)

        self.setLayout(layout)

    def set_window_properties(self):
        # 设置窗口透明度
        self.setWindowOpacity(0.9)
        # 调整窗口大小
        self.adjustSize()